package com.mudalov.rec.dao.model.study;

import com.mudalov.rec.dao.interfaces.IClonable;
import java.io.Serializable;
import java.util.Set;

import com.mudalov.rec.dao.model.user.Teacher;
import java.util.HashSet;

public class StudyProgram implements Serializable, IClonable<StudyProgram> {
	
	private static final long serialVersionUID = 7012871124444020853L;

	private Long id;

    private String name;

	private Subject subject;
	
	private Set<Test> tests;
	
	private Set<Material> materials;
	
	private Teacher teacher;
	
	public StudyProgram() {
        materials = new HashSet<Material>();
        tests = new HashSet<Test>();
    }

	public StudyProgram(Set<Material> materials, Subject subject,
			Set<Test> tests) {
		this.materials = materials;
		this.subject = subject;
		this.tests = tests;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Set<Test> getTests() {
		return tests;
	}

	public void setTests(Set<Test> tests) {
		this.tests = tests;
	}

	public Set<Material> getMaterials() {
		return materials;
	}

	public void setMaterials(Set<Material> materials) {
		this.materials = materials;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

    public String getTeacherName() {
        return this.getTeacher() != null ? this.getTeacher().getFullName() : "";
    }

    public void setTeacherName(String name) {
        // nothing to do
    }

    public String getSubjectText() {
        return this.getSubject() != null ? this.getSubject().getText() : "";
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result
				+ ((materials == null) ? 0 : materials.hashCode());
		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
		result = prime * result + ((tests == null) ? 0 : tests.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof StudyProgram))
			return false;
		StudyProgram other = (StudyProgram) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (materials == null) {
			if (other.materials != null)
				return false;
		} else if (!materials.equals(other.materials))
			return false;
		if (subject == null) {
			if (other.subject != null)
				return false;
		} else if (!subject.equals(other.subject))
			return false;
		if (tests == null) {
			if (other.tests != null)
				return false;
		} else if (!tests.equals(other.tests))
			return false;
		if (teacher == null) {
			if (other.teacher != null)
				return false;
		} else if (!teacher.equals(other.teacher))
			return false;
		return true;
	}

    public StudyProgram getClone() {
        StudyProgram clone = new StudyProgram();
        clone.setId(this.getId());
        clone.setName(this.getName());
        if (this.getSubject() != null) {
            clone.setSubject(this.getSubject().getClone());
        }
        if (this.getTeacher() != null) {
            clone.setTeacher(this.getTeacher().getClone());
        }
        for (Test test : this.getTests()) {
            clone.getTests().add(test.getClone());
        }
        for (Material material : this.getMaterials()) {
            clone.getMaterials().add(material.getClone());
        }
        return clone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    
}
